package arraylistdemo;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;

/**
 * @Author 12629
 * @Date 2022/3/12 11:43
 * @Description：
 */
public class Test {

    public static void main(String[] args) {
        LinkedList<Integer> linkedList = new LinkedList<>();
        linkedList.add(1);
        linkedList.add(2);
        linkedList.add(3);
        for (int i = 0; i < linkedList.size(); i++) {
            System.out.print(linkedList.get(i)+" ");
        }
        System.out.println();
        for (Integer x:linkedList) {
            System.out.print(x+" ");
        }
        System.out.println();
        Iterator<Integer> it = linkedList.listIterator();
        while (it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        //倒着遍历
        ListIterator<Integer> it2 = linkedList.listIterator(linkedList.size());
        while (it2.hasPrevious()) {
            System.out.print(it2.previous()+" ");
        }
    }
    public static void main1(String[] args) {
        List<Integer> list = new LinkedList<>();

        LinkedList<Integer> linkedList = new LinkedList<>();
        linkedList.add(1);
        linkedList.add(2);
        linkedList.add(3);
        System.out.println(linkedList);

        System.out.println(linkedList.get(0));
        System.out.println(linkedList.remove(1));
        System.out.println(linkedList);
        //设置原来的值为99，并且返回原来的值
        System.out.println(linkedList.set(1,99));
        System.out.println(linkedList);
        linkedList.clear();
        System.out.println(linkedList);

    }
}
